package com.hsogoo.collate.batch;

import com.hsogoo.collate.service.CollateDownloadService;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Author huangsaigang
 * Created @2019-10-28.
 */
@Slf4j
@Setter
public class DownloadCollateFileTasklet implements Tasklet {

    @Autowired
    private CollateDownloadService downloadService;

    @Override
    public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {

        log.info("DownloadCollateFileTasklet.executing...");
        JobParameters jobParameters = stepContribution.getStepExecution().getJobExecution().getJobParameters();

        //对账文件地址
        String targetCollateFile = jobParameters.getString("targetCollateFile");
        //对账文件服务器
        String targetServer = jobParameters.getString("targetServer");
        //对账文件保存的本地路径
        String localFilePath = jobParameters.getString("localFilePath");
        //下载对账文件到应用服务器
        downloadService.downloadCollateFile(targetServer, localFilePath, targetCollateFile);

        return RepeatStatus.FINISHED;
    }
}
